package com.zd.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zd.entity.User;
import com.zd.service.updateUserService;
import com.zd.service.impl.updateUserServiceImpl;

/**
 * Servlet implementation class updateServlet
 */
@WebServlet("/updateServlet")
public class updateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public updateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//获取user参数
		String userName = (String)request.getParameter("userName");
		String userPass = (String)request.getParameter("userPass");
		System.out.println(userName+","+userPass);
		String userPhoneNum = (String)request.getParameter("userPhoneNum");
		User oldUser = (User)request.getSession().getAttribute("user");
		Integer userId = oldUser.getUserId();
		User newUser = new User(userId,userName,userPass,userPhoneNum,oldUser.getExpValue(),oldUser.getStatus(),oldUser.getRisgterTime(),oldUser.getAdmin(),oldUser.getVip());
		
		updateUserService uus = new updateUserServiceImpl();
		uus.update(newUser);
		
		request.getRequestDispatcher("UserCenterServlet").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
